[Solved]

您所在的位置:网站首页 java csvwriter [Solved]

[Solved]

2023-03-30 00:55| 来源: 网络整理| 查看: 265

I don't think that your example is correct, because you're passing a ZipOutputStream directly to CsvWriter. Assuming you are using OpenCSV, the CsvWriter constructor needs a Writer, not an OutputStream.

In Java, I/O streams are either byte streams, which are raw data; or character streams, which consist of Unicode characters. In order to convert from one to the other, you must supply a character encoding, which tells it how to convert characters to/from bytes. (If you don't provide one, then Java will use the default character encoding — which depends on the platform but is commonly UTF-8.) InputStream and OutputStream are byte streams, while the corresponding character streams are called Reader and Writer.

You have a ZipOutputStream, which is a byte stream. The OpenCSV CsvWriter constructor requires a Writer, a character stream, which makes sense because CSV is a text format. (I imagine this would be true of other CsvWriter implementations as well.) You should wrap your ZipOutputStream in an instance of OutputStreamWriter, which will convert the CSV characters into bytes. You can specify the character encoding in the OutputStreamWriter constructor.



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3